//
//  DMFacebookCallbackForwarder.m
//  DualMediationSDK
//
//  Facebook回调转发器实现
//

#import "DMFacebookCallbackForwarder.h"
#import "../Core/DMLifecycleDelegateRegistry.h"

#pragma mark - Facebook转发统计信息实现

@implementation DMFacebookForwardStatistics

- (NSTimeInterval)averageForwardTime {
    if (self.successfulForwards == 0) {
        return 0;
    }
    return self.totalForwardTime / self.successfulForwards;
}

- (NSString *)description {
    return [NSString stringWithFormat:@"<DMFacebookForwardStatistics: total=%lu, success=%lu, failed=%lu, avgTime=%.3fms>",
            (unsigned long)self.totalForwards,
            (unsigned long)self.successfulForwards,
            (unsigned long)self.failedForwards,
            self.averageForwardTime * 1000];
}

@end

#pragma mark - Facebook转发日志项

@interface DMFacebookForwardLogItem : NSObject
@property (nonatomic, strong) NSString *callbackType;
@property (nonatomic, strong) NSDate *timestamp;
@property (nonatomic, assign) DMFacebookForwardResult result;
@property (nonatomic, assign) NSTimeInterval duration;
@property (nonatomic, assign) NSUInteger handlerCount;
@property (nonatomic, strong, nullable) NSString *errorDescription;
@property (nonatomic, strong, nullable) id data;
@end

@implementation DMFacebookForwardLogItem
@end

#pragma mark - 待转发Facebook回调项

@interface DMPendingFacebookForward : NSObject
@property (nonatomic, strong) NSString *callbackType;
@property (nonatomic, strong, nullable) id data;
@property (nonatomic, strong) NSDate *timestamp;
@property (nonatomic, copy, nullable) void(^completion)(DMFacebookForwardResult result);
@end

@implementation DMPendingFacebookForward
@end

#pragma mark - Facebook回调转发器实现

@interface DMFacebookCallbackForwarder ()

// 转发控制
@property (nonatomic, assign) BOOL forwardingPaused;
@property (nonatomic, strong) NSMutableArray<DMPendingFacebookForward *> *pendingForwards;

// 统计信息
@property (nonatomic, strong) DMFacebookForwardStatistics *statistics;
@property (nonatomic, strong) NSMutableArray<DMFacebookForwardLogItem *> *forwardLog;
@property (nonatomic, assign) NSUInteger maxLogCount;

// 错误处理
@property (nonatomic, copy, nullable) DMFacebookForwardErrorHandler errorHandler;

// 线程安全
@property (nonatomic, strong) dispatch_queue_t forwardQueue;
@property (nonatomic, strong) dispatch_queue_t statisticsQueue;
@property (nonatomic, strong) dispatch_group_t forwardGroup;

@end

@implementation DMFacebookCallbackForwarder

static DMFacebookCallbackForwarder *_sharedForwarder = nil;
static dispatch_once_t onceToken;

#pragma mark - 单例实现

+ (instancetype)sharedForwarder {
    dispatch_once(&onceToken, ^{
        _sharedForwarder = [[self alloc] init];
    });
    return _sharedForwarder;
}

- (instancetype)init {
    self = [super init];
    if (self) {
        [self setupForwarder];
    }
    return self;
}

- (void)setupForwarder {
    // 创建队列
    _forwardQueue = dispatch_queue_create("com.dualmediationsdk.facebook.forwarder", DISPATCH_QUEUE_CONCURRENT);
    _statisticsQueue = dispatch_queue_create("com.dualmediationsdk.facebook.statistics", DISPATCH_QUEUE_SERIAL);
    _forwardGroup = dispatch_group_create();
    
    // 初始化配置
    _asyncForwardEnabled = YES;
    _forwardTimeout = 5.0;
    _statisticsEnabled = NO;
    _debugModeEnabled = NO;
    _forwardingPaused = NO;
    
    // 初始化容器
    _pendingForwards = [NSMutableArray array];
    _statistics = [[DMFacebookForwardStatistics alloc] init];
    _forwardLog = [NSMutableArray array];
    _maxLogCount = 300;
}

#pragma mark - Facebook登录回调转发

- (DMFacebookForwardResult)forwardLoginSuccess:(DMLoginResponse *)result {
    return [self forwardGenericCallback:@"FacebookLoginSuccess" data:result];
}

- (DMFacebookForwardResult)forwardLoginFailure:(NSError *)error {
    return [self forwardGenericCallback:@"FacebookLoginFailure" data:error];
}

- (DMFacebookForwardResult)forwardLoginCancel {
    return [self forwardGenericCallback:@"FacebookLoginCancel" data:nil];
}

- (void)forwardLoginResultAsync:(nullable DMLoginResponse *)result
                          error:(nullable NSError *)error
                      cancelled:(BOOL)cancelled
                     completion:(nullable void(^)(DMFacebookForwardResult result))completion {
    NSString *callbackType;
    id data = nil;
    
    if (cancelled) {
        callbackType = @"FacebookLoginCancel";
    } else if (error) {
        callbackType = @"FacebookLoginFailure";
        data = error;
    } else {
        callbackType = @"FacebookLoginSuccess";
        data = result;
    }
    
    [self forwardGenericCallbackAsync:callbackType data:data completion:completion];
}

#pragma mark - Facebook分享回调转发

- (DMFacebookForwardResult)forwardShareSuccess:(NSDictionary *)result {
    return [self forwardGenericCallback:@"FacebookShareSuccess" data:result];
}

- (DMFacebookForwardResult)forwardShareFailure:(NSError *)error {
    return [self forwardGenericCallback:@"FacebookShareFailure" data:error];
}

- (DMFacebookForwardResult)forwardShareCancel {
    return [self forwardGenericCallback:@"FacebookShareCancel" data:nil];
}

- (void)forwardShareResultAsync:(nullable NSDictionary *)result
                          error:(nullable NSError *)error
                      cancelled:(BOOL)cancelled
                     completion:(nullable void(^)(DMFacebookForwardResult result))completion {
    NSString *callbackType;
    id data = nil;
    
    if (cancelled) {
        callbackType = @"FacebookShareCancel";
    } else if (error) {
        callbackType = @"FacebookShareFailure";
        data = error;
    } else {
        callbackType = @"FacebookShareSuccess";
        data = result;
    }
    
    [self forwardGenericCallbackAsync:callbackType data:data completion:completion];
}

#pragma mark - Facebook Graph API回调转发

- (DMFacebookForwardResult)forwardGraphAPISuccess:(id)result request:(NSDictionary *)request {
    NSDictionary *data = @{
        @"result": result,
        @"request": request
    };
    return [self forwardGenericCallback:@"FacebookGraphAPISuccess" data:data];
}

- (DMFacebookForwardResult)forwardGraphAPIFailure:(NSError *)error request:(NSDictionary *)request {
    NSDictionary *data = @{
        @"error": error,
        @"request": request
    };
    return [self forwardGenericCallback:@"FacebookGraphAPIFailure" data:data];
}

#pragma mark - Facebook应用事件回调转发

- (DMFacebookForwardResult)forwardAppEventLogged:(NSString *)eventName
                                      parameters:(nullable NSDictionary *)parameters
                                         success:(BOOL)success {
    NSDictionary *data = @{
        @"eventName": eventName,
        @"parameters": parameters ?: @{},
        @"success": @(success)
    };
    return [self forwardGenericCallback:@"FacebookAppEventLogged" data:data];
}

#pragma mark - 通用Facebook回调转发

- (DMFacebookForwardResult)forwardGenericCallback:(NSString *)callbackType data:(nullable id)data {
    if (self.forwardingPaused) {
        [self logDebug:@"Facebook forwarding paused, queuing callback: %@", callbackType];
        [self queuePendingForward:callbackType data:data completion:nil];
        return DMFacebookForwardResultSuccess;
    }
    
    NSDate *startTime = [NSDate date];
    DMFacebookForwardLogItem *logItem = [self createLogItemForCallback:callbackType timestamp:startTime];
    logItem.data = data;
    
    // 获取Facebook回调处理器
    NSArray<id<DMFacebookCallbackDelegate>> *handlers = [[DMLifecycleDelegateRegistry sharedRegistry] getAllFacebookDelegates];
    
    if (handlers.count == 0) {
        logItem.result = DMFacebookForwardResultNoHandlers;
        logItem.duration = [[NSDate date] timeIntervalSinceDate:startTime];
        [self addLogItem:logItem];
        return DMFacebookForwardResultNoHandlers;
    }
    
    logItem.handlerCount = handlers.count;
    
    // 分发Facebook回调
    DMFacebookForwardResult result = [self performForwardDispatch:handlers 
                                                     callbackType:callbackType 
                                                             data:data];
    
    // 更新日志和统计
    logItem.result = result;
    logItem.duration = [[NSDate date] timeIntervalSinceDate:startTime];
    [self addLogItem:logItem];
    [self updateStatistics:result duration:logItem.duration];
    
    return result;
}

- (void)forwardGenericCallbackAsync:(NSString *)callbackType
                               data:(nullable id)data
                         completion:(nullable void(^)(DMFacebookForwardResult result))completion {
    if (!self.asyncForwardEnabled) {
        DMFacebookForwardResult result = [self forwardGenericCallback:callbackType data:data];
        if (completion) {
            completion(result);
        }
        return;
    }
    
    dispatch_group_enter(self.forwardGroup);
    
    dispatch_async(self.forwardQueue, ^{
        DMFacebookForwardResult result = [self forwardGenericCallback:callbackType data:data];
        
        dispatch_group_leave(self.forwardGroup);
        
        if (completion) {
            dispatch_async(dispatch_get_main_queue(), ^{
                completion(result);
            });
        }
    });
}

#pragma mark - Facebook回调分发核心逻辑

- (DMFacebookForwardResult)performForwardDispatch:(NSArray<id<DMFacebookCallbackDelegate>> *)handlers 
                                      callbackType:(NSString *)callbackType 
                                              data:(nullable id)data {
    NSUInteger successCount = 0;
    NSUInteger failureCount = 0;
    
    for (id<DMFacebookCallbackDelegate> handler in handlers) {
        BOOL success = [self dispatchToFacebookHandler:handler callbackType:callbackType data:data];
        if (success) {
            successCount++;
        } else {
            failureCount++;
        }
    }
    
    return [self determineForwardResult:successCount failureCount:failureCount totalCount:handlers.count];
}

- (BOOL)dispatchToFacebookHandler:(id<DMFacebookCallbackDelegate>)handler 
                     callbackType:(NSString *)callbackType 
                             data:(nullable id)data {
    @try {
        // 根据回调类型调用相应的方法
        if ([callbackType isEqualToString:@"FacebookLoginSuccess"]) {
            if ([handler respondsToSelector:@selector(onFacebookLoginSuccess:)]) {
                [handler onFacebookLoginSuccess:(DMLoginResponse *)data];
                return YES;
            }
        } else if ([callbackType isEqualToString:@"FacebookLoginFailure"]) {
            if ([handler respondsToSelector:@selector(onFacebookLoginError:)]) {
                [handler onFacebookLoginError:(NSError *)data];
                return YES;
            }
        } else if ([callbackType isEqualToString:@"FacebookLoginCancel"]) {
            if ([handler respondsToSelector:@selector(onFacebookLoginCancel)]) {
                [handler onFacebookLoginCancel];
                return YES;
            }
        } else if ([callbackType isEqualToString:@"FacebookShareSuccess"]) {
            if ([handler respondsToSelector:@selector(onFacebookShareSuccess:)]) {
                [handler onFacebookShareSuccess:(NSDictionary *)data];
                return YES;
            }
        } else if ([callbackType isEqualToString:@"FacebookShareFailure"]) {
            if ([handler respondsToSelector:@selector(onFacebookShareFailure:)]) {
                [handler onFacebookShareFailure:(NSError *)data];
                return YES;
            }
        } else if ([callbackType isEqualToString:@"FacebookShareCancel"]) {
            if ([handler respondsToSelector:@selector(onFacebookShareCancel)]) {
                [handler onFacebookShareCancel];
                return YES;
            }
        } else if ([callbackType isEqualToString:@"FacebookGraphAPISuccess"]) {
            if ([handler respondsToSelector:@selector(onFacebookGraphAPISuccess:request:)]) {
                NSDictionary *dict = (NSDictionary *)data;
                [handler onFacebookGraphAPISuccess:dict[@"result"] request:dict[@"request"]];
                return YES;
            }
        } else if ([callbackType isEqualToString:@"FacebookGraphAPIFailure"]) {
            if ([handler respondsToSelector:@selector(onFacebookGraphAPIFailure:request:)]) {
                NSDictionary *dict = (NSDictionary *)data;
                [handler onFacebookGraphAPIFailure:dict[@"error"] request:dict[@"request"]];
                return YES;
            }
        } else if ([callbackType isEqualToString:@"FacebookAppEventLogged"]) {
            if ([handler respondsToSelector:@selector(onFacebookAppEventLogged:parameters:success:)]) {
                NSDictionary *dict = (NSDictionary *)data;
                [handler onFacebookAppEventLogged:dict[@"eventName"] 
                                        parameters:dict[@"parameters"] 
                                           success:[dict[@"success"] boolValue]];
                return YES;
            }
        }
        
        return NO; // 处理器不支持该回调类型
        
    } @catch (NSException *exception) {
        [self handleForwardError:[NSError errorWithDomain:@"DMFacebookCallbackForwarder" 
                                                     code:-1 
                                                 userInfo:@{NSLocalizedDescriptionKey: exception.reason ?: @"Unknown error"}]
                    callbackType:callbackType 
                            data:data];
        return NO;
    }
}

- (DMFacebookForwardResult)determineForwardResult:(NSUInteger)successCount 
                                     failureCount:(NSUInteger)failureCount 
                                       totalCount:(NSUInteger)totalCount {
    if (totalCount == 0) {
        return DMFacebookForwardResultNoHandlers;
    }
    
    if (failureCount == 0) {
        return DMFacebookForwardResultSuccess;
    } else if (successCount > 0) {
        return DMFacebookForwardResultPartialFailure;
    } else {
        return DMFacebookForwardResultFailure;
    }
}

#pragma mark - 转发控制

- (void)pauseForwarding {
    dispatch_barrier_async(self.forwardQueue, ^{
        self.forwardingPaused = YES;
        [self logDebug:@"Facebook forwarding paused"];
    });
}

- (void)resumeForwarding {
    dispatch_barrier_async(self.forwardQueue, ^{
        self.forwardingPaused = NO;
        [self logDebug:@"Facebook forwarding resumed"];
        
        // 处理待转发的回调
        [self processPendingForwards];
    });
}

- (BOOL)isForwardingPaused {
    __block BOOL paused = NO;
    dispatch_sync(self.forwardQueue, ^{
        paused = self.forwardingPaused;
    });
    return paused;
}

- (void)clearPendingForwards {
    dispatch_barrier_async(self.forwardQueue, ^{
        [self.pendingForwards removeAllObjects];
        [self logDebug:@"Cleared all pending Facebook forwards"];
    });
}

- (NSUInteger)getPendingForwardCount {
    __block NSUInteger count = 0;
    dispatch_sync(self.forwardQueue, ^{
        count = self.pendingForwards.count;
    });
    return count;
}

- (void)queuePendingForward:(NSString *)callbackType data:(nullable id)data completion:(nullable void(^)(DMFacebookForwardResult result))completion {
    dispatch_barrier_async(self.forwardQueue, ^{
        DMPendingFacebookForward *pendingForward = [[DMPendingFacebookForward alloc] init];
        pendingForward.callbackType = callbackType;
        pendingForward.data = data;
        pendingForward.timestamp = [NSDate date];
        pendingForward.completion = completion;
        
        [self.pendingForwards addObject:pendingForward];
    });
}

- (void)processPendingForwards {
    NSArray<DMPendingFacebookForward *> *forwards = [self.pendingForwards copy];
    [self.pendingForwards removeAllObjects];
    
    for (DMPendingFacebookForward *forward in forwards) {
        DMFacebookForwardResult result = [self forwardGenericCallback:forward.callbackType data:forward.data];
        
        if (forward.completion) {
            dispatch_async(dispatch_get_main_queue(), ^{
                forward.completion(result);
            });
        }
    }
    
    [self logDebug:@"Processed %lu pending Facebook forwards", (unsigned long)forwards.count];
}

#pragma mark - 错误处理

- (void)setForwardErrorHandler:(nullable DMFacebookForwardErrorHandler)errorHandler {
    self.errorHandler = errorHandler;
}

- (void)handleForwardError:(NSError *)error callbackType:(NSString *)callbackType data:(nullable id)data {
    [self logDebug:@"Facebook forward error for type %@: %@", callbackType, error.localizedDescription];
    
    if (self.errorHandler) {
        dispatch_async(dispatch_get_main_queue(), ^{
            self.errorHandler(error, callbackType, data);
        });
    }
}

#pragma mark - 统计和日志

- (void)updateStatistics:(DMFacebookForwardResult)result duration:(NSTimeInterval)duration {
    if (!self.statisticsEnabled) {
        return;
    }
    
    dispatch_async(self.statisticsQueue, ^{
        self.statistics.totalForwards++;
        self.statistics.totalForwardTime += duration;
        
        if (result == DMFacebookForwardResultSuccess || result == DMFacebookForwardResultPartialFailure) {
            self.statistics.successfulForwards++;
        } else {
            self.statistics.failedForwards++;
        }
    });
}

- (DMFacebookForwardLogItem *)createLogItemForCallback:(NSString *)callbackType timestamp:(NSDate *)timestamp {
    DMFacebookForwardLogItem *item = [[DMFacebookForwardLogItem alloc] init];
    item.callbackType = callbackType;
    item.timestamp = timestamp;
    return item;
}

- (void)addLogItem:(DMFacebookForwardLogItem *)logItem {
    if (!self.debugModeEnabled) {
        return;
    }
    
    dispatch_async(self.statisticsQueue, ^{
        [self.forwardLog addObject:logItem];
        
        // 限制日志数量
        while (self.forwardLog.count > self.maxLogCount) {
            [self.forwardLog removeObjectAtIndex:0];
        }
    });
}

- (nullable DMFacebookForwardStatistics *)getForwardStatistics {
    if (!self.statisticsEnabled) {
        return nil;
    }
    
    __block DMFacebookForwardStatistics *stats = nil;
    dispatch_sync(self.statisticsQueue, ^{
        stats = [self.statistics copy];
    });
    return stats;
}

- (void)resetForwardStatistics {
    dispatch_async(self.statisticsQueue, ^{
        self.statistics = [[DMFacebookForwardStatistics alloc] init];
    });
}

- (NSDictionary *)getPerformanceReport {
    __block NSDictionary *report = nil;
    dispatch_sync(self.statisticsQueue, ^{
        report = @{
            @"totalForwards": @(self.statistics.totalForwards),
            @"successfulForwards": @(self.statistics.successfulForwards),
            @"failedForwards": @(self.statistics.failedForwards),
            @"averageForwardTime": @(self.statistics.averageForwardTime),
            @"totalForwardTime": @(self.statistics.totalForwardTime),
            @"pendingForwards": @([self getPendingForwardCount]),
            @"forwardingPaused": @(self.forwardingPaused),
            @"asyncForwardEnabled": @(self.asyncForwardEnabled)
        };
    });
    return report;
}

- (NSArray *)getForwardHistory:(NSUInteger)limit {
    __block NSArray *history = nil;
    
    dispatch_sync(self.statisticsQueue, ^{
        if (limit == 0 || limit >= self.forwardLog.count) {
            history = [self.forwardLog copy];
        } else {
            NSRange range = NSMakeRange(self.forwardLog.count - limit, limit);
            history = [self.forwardLog subarrayWithRange:range];
        }
        
        // 按时间倒序排列
        history = [history sortedArrayUsingComparator:^NSComparisonResult(DMFacebookForwardLogItem *obj1, DMFacebookForwardLogItem *obj2) {
            return [obj2.timestamp compare:obj1.timestamp];
        }];
    });
    
    return history;
}

#pragma mark - 调试支持

- (NSDictionary *)getDebugInfo {
    return @{
        @"forwardingPaused": @(self.forwardingPaused),
        @"asyncForwardEnabled": @(self.asyncForwardEnabled),
        @"statisticsEnabled": @(self.statisticsEnabled),
        @"debugModeEnabled": @(self.debugModeEnabled),
        @"forwardTimeout": @(self.forwardTimeout),
        @"pendingForwards": @([self getPendingForwardCount]),
        @"logCount": @(self.forwardLog.count),
        @"maxLogCount": @(self.maxLogCount)
    };
}

- (BOOL)validateForwarderState {
    // 验证配置参数
    if (self.forwardTimeout <= 0) {
        [self logDebug:@"Invalid forward timeout: %f", self.forwardTimeout];
        return NO;
    }
    
    // 验证队列状态
    if (!self.forwardQueue || !self.statisticsQueue || !self.forwardGroup) {
        [self logDebug:@"Missing required forward queues or group"];
        return NO;
    }
    
    return YES;
}

- (nullable NSString *)exportForwardLogWithLimit:(NSUInteger)limit {
    __block NSString *jsonString = nil;
    
    dispatch_sync(self.statisticsQueue, ^{
        NSArray *logsToExport = self.forwardLog;
        if (limit > 0 && limit < logsToExport.count) {
            NSRange range = NSMakeRange(logsToExport.count - limit, limit);
            logsToExport = [logsToExport subarrayWithRange:range];
        }
        
        NSMutableArray *logArray = [NSMutableArray array];
        for (DMFacebookForwardLogItem *item in logsToExport) {
            NSDictionary *logDict = @{
                @"callbackType": item.callbackType,
                @"timestamp": @([item.timestamp timeIntervalSince1970]),
                @"result": @(item.result),
                @"duration": @(item.duration),
                @"handlerCount": @(item.handlerCount),
                @"error": item.errorDescription ?: [NSNull null],
                @"hasData": @(item.data != nil)
            };
            [logArray addObject:logDict];
        }
        
        NSDictionary *exportData = @{
            @"exportTime": @([[NSDate date] timeIntervalSince1970]),
            @"logCount": @(logArray.count),
            @"logs": logArray
        };
        
        NSError *error = nil;
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:exportData
                                                           options:NSJSONWritingPrettyPrinted
                                                             error:&error];
        
        if (jsonData && !error) {
            jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
        } else {
            [self logDebug:@"Failed to export Facebook forward log as JSON: %@", error.localizedDescription];
        }
    });
    
    return jsonString;
}

- (DMFacebookForwardResult)simulateCallback:(NSString *)callbackType data:(nullable id)data {
    [self logDebug:@"Simulating Facebook callback: %@", callbackType];
    return [self forwardGenericCallback:callbackType data:data];
}

- (void)logDebug:(NSString *)format, ... {
    if (!self.debugModeEnabled) {
        return;
    }
    
    va_list args;
    va_start(args, format);
    NSString *message = [[NSString alloc] initWithFormat:format arguments:args];
    va_end(args);
    
    NSLog(@"[DMFacebookCallbackForwarder] %@", message);
}

#pragma mark - Facebook URL处理

- (BOOL)handleOpenURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
    [self logDebug:@"Handling Facebook open URL: %@", url];
    
    // 这里应该调用Facebook SDK的URL处理方法
    // 由于这是一个转发器，我们主要负责记录和转发
    
    // 转发URL处理事件给所有Facebook代理
    NSDictionary *data = @{
        @"url": url,
        @"options": options ?: @{}
    };
    
    DMFacebookForwardResult result = [self forwardGenericCallback:@"FacebookOpenURL" data:data];
    
    // 返回是否有处理器成功处理了这个URL
    return (result == DMFacebookForwardResultSuccess || result == DMFacebookForwardResultPartialFailure);
}

- (BOOL)handleContinueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray<id<UIUserActivityRestoring>> * _Nullable restorableObjects))restorationHandler {
    [self logDebug:@"Handling Facebook continue user activity: %@", userActivity.activityType];
    
    // 这里应该调用Facebook SDK的用户活动处理方法
    // 由于这是一个转发器，我们主要负责记录和转发
    
    // 转发用户活动事件给所有Facebook代理
    NSDictionary *data = @{
        @"userActivity": userActivity,
        @"activityType": userActivity.activityType ?: @"",
        @"webpageURL": userActivity.webpageURL ? userActivity.webpageURL.absoluteString : [NSNull null]
    };
    
    DMFacebookForwardResult result = [self forwardGenericCallback:@"FacebookContinueUserActivity" data:data];
    
    // 如果有恢复处理器，调用它
    if (restorationHandler) {
        restorationHandler(nil);
    }
    
    // 返回是否有处理器成功处理了这个用户活动
    return (result == DMFacebookForwardResultSuccess || result == DMFacebookForwardResultPartialFailure);
}

@end